import { RestDto } from "~/rest";
import { ExtOwner } from "./core.define";
import { UserGateway } from "./dto.user";
import { User } from "./schema.user";

export const UserRpcGetUserInfoByIdPath = `${UserGateway.path}/getUserInfoById`;
export type getUserInfoByIdRpcDto = { uuid32: User["uuid32"] };

export const UserRpcGetUserInfoBySessionIdPath = `${UserGateway.path}/getUserInfoBySessionId`;
export type getUserInfoBySessionIdRpcDto = { SessionId: string };

export const UserRpcGetFirstUserPath = `${UserGateway.path}/getFirstUser`;
export type getFirstUserRpcDto = {};

export const UserRpcGetMasterPath = `${UserGateway.path}/getMaster`;
export const UserRpcGetDeriveUserListPath = `${UserGateway.path}/getDeriveUserList`;

export const UserRpcIsSameMasterPath = `${UserGateway.path}/isSameMaster`;
export type isSameMasterRpcDto = { source: ExtOwner };

export interface UserRpcInterface<T> {
  /** 获取具体的用户信息，耗时较长（找不到会报错） */
  getUserInfoById(dto: T & getUserInfoByIdRpcDto): Promise<User>;

  /** 快速鉴权（找不到会报错）鉴权会频繁调用，不要长期记录日志 */
  getUserInfoBySessionId(dto: getUserInfoBySessionIdRpcDto): Promise<Pick<User, "uuid32" | "type">>;

  /** 获取第一个用户（找不到会报错） */
  getFirstUser(dto: T & getFirstUserRpcDto): Promise<{ uuid32: User["uuid32"] }>;

  /** 获取主账号信息（找不到会报错）*/
  getMaster(dto: RestDto): Promise<Pick<User, "uuid32">>;

  /** 获取所有辅助账号 */
  getDeriveUserList(dto: RestDto): Promise<User[]>;

  /** 资源的所属权，要和访客（或者访客的主账号）一致（否则会报错）*/
  isSameMaster(dto: T & isSameMasterRpcDto): Promise<void>;
}
